
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?php echo $title;?></title>
    <!-- 设置缩放 -->
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
    <meta name="format-detection" content="telephone=no" />
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- icon -->
    <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />
    <style>
        .form_item_table label{display: inline-block;margin:5px;}
        .con_box table input[type="checkbox"]{margin:0 3px 0 0; width:12px;height:12px;}
        .con_box .table_th_td td, .table_th_td th {white-space: normal;text-overflow: inherit; }
        .con_box .form_box table td .display_no{display: none;}
    </style>
</head>
<body>
<?php
$userLevel = getUserLevel();
$info = isset($info) ? $info : array();
$classlist = isset($classlist) ? $classlist : array();
$classlistFuns = isset($classlistFuns) ? $classlistFuns : array();
// 拆解权限功能分组
$classFuns = $essayFuns = $otherFuns = array();
if(isset($rule)){
    foreach($rule as $k=>$v){
        if($v['types'] == 1){
            $classFuns[] = $v;
        }else if($v['types'] == 2){
            $essayFuns[] = $v;
        }else if($v['types'] == 3){
            $otherFuns[] = $v;
        }
    }
}

// 不是开发者屏蔽一些
$adminDisplay = $userLevel != 1 ? 'display_no' : '';
//历史权限
$oldClass = isset($info['menu_ids']) ? explode(',',$info['menu_ids']) : array();
$oldClassfuns = isset($info['classfun']) ? explode(',',$info['classfun']) : array();
$oldEssayfun = isset($info['essayfun']) ? explode(',',$info['essayfun']) : array();
?>
<div class="con_box">

    <form class="form_box">
        <div class="form_item_table">
            <input type="hidden" name="id" value="<?php echo $info['id'];?>">
            <!----------顶部菜单权限---------->
            <div class="titleH18">顶部菜单权限</div><br>
            <table class="table_th_td" style="">
                <tr class="weight400">
                    <th>菜单名称</th>
                    <th>菜单权限</th>
                    <th>文章权限</th>
                </tr>
                <?php
                foreach($classlist as $v){
                    if($v['navtype'] == 1){
                        $level = $v['level']*2;
                        $str = str_pad("",$level, '-',STR_PAD_LEFT );
                        $fontb = $v['fid'] == 0 ? 'fontb' : '';
                        $menuId = $v['id'];
                        $menuname = $v['menuname'];
                        // 顶部菜单通用权限
                        if($v['setflag'] == 1){
                            $classFunHtml = '';
                            foreach($classFuns as $f){
                                if(!$f['menu_id'] || $f['menu_id'] == $menuId){
                                    $powerFunStr = $menuId.'_'.$f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedF = in_array($powerFunStr, $oldClassfuns) ? 'checked="checked"' : '';
                                    $classFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="classfun[]" value="'.$powerFunStr.'" '.$checkedF.'>'.$f['title'].'</label>';
                                }
                            }
                            $essayFunHtml = '';
                            foreach($essayFuns as $f){
                                if(!$f['menu_id'] || $f['menu_id'] == $menuId) {
                                    $powerFunStr = $menuId . '_' . $f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedE = in_array($powerFunStr, $oldEssayfun) ? 'checked="checked"' : '';
                                    $essayFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="essayfun[]" value="' . $powerFunStr . '" '.$checkedE.'>' . $f['title'] . '</label>';
                                }
                            }
                        }
                        // 顶部菜单其他权限
                        if($v['setflag'] == 2){
                            $menuId = $v['setpath'];
                            $classFunHtml = '';
                            foreach($otherFuns as $f){
                                if($f['menu_id'] == $menuId) {
                                    $powerFunStr = $menuId . '_' . $f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedF = in_array($powerFunStr, $oldClassfuns) ? 'checked="checked"' : '';
                                    $classFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="classfun[]" value="' . $powerFunStr . '" '.$checkedF.'>' . $f['title'] . '</label>';
                                }
                            }
                            $essayFunHtml = '';
                        }
                        $checkedC = in_array($menuId, $oldClass) ? 'checked="checked"' : '';
                        echo <<<html
                <tr>
                    <td class="$fontb"><label><input type="checkbox" name="classs[]" value="$menuId" $checkedC >$str $menuname</label></td>
                    <td>
                        $classFunHtml
                    </td>
                    <td>
                        $essayFunHtml
                    </td>
                </tr>
html;
                    }
                }
                ?>
            </table>

            <!----------左侧菜单权限---------->
            <br><div class="titleH18">左侧菜单权限</div><br>
            <table class="table_th_td" style="">
                <tr class="weight400">
                    <th>菜单名称</th>
                    <th>菜单权限</th>
                    <th>文章权限</th>
                </tr>
                <?php
                foreach($classlist as $v){
                    if($v['navtype'] == 2){
                        $level = $v['level']*2;
                        $str = str_pad("",$level, '-',STR_PAD_LEFT );
                        $fontb = $v['fid'] == 0 ? 'fontb' : '';
                        $menuId = $v['id'];
                        $menuname = $v['menuname'];
                        // 左侧菜单通用权限
                        if($v['setflag'] == 1){
                            $classFunHtml = '';
                            foreach($classFuns as $f){
                                if(!$f['menu_id'] || $f['menu_id'] == $menuId){
                                    $powerFunStr = $menuId.'_'.$f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedF = in_array($powerFunStr, $oldClassfuns) ? 'checked="checked"' : '';
                                    $classFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="classfun[]" value="'.$powerFunStr.'" '.$checkedF.'>'.$f['title'].'</label>';
                                }
                            }
                            $essayFunHtml = '';
                            foreach($essayFuns as $f){
                                if(!$f['menu_id'] || $f['menu_id'] == $menuId) {
                                    $powerFunStr = $menuId . '_' . $f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedE = in_array($powerFunStr, $oldEssayfun) ? 'checked="checked"' : '';
                                    $essayFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="essayfun[]" value="' . $powerFunStr . '" '.$checkedE.'>' . $f['title'] . '</label>';
                                }
                            }
                        }
                        // 左侧菜单其他权限
                        if($v['setflag'] == 2){
                            $menuId = $v['setpath'];
                            $classFunHtml = '';
                            foreach($otherFuns as $f){
                                if($f['menu_id'] == $menuId) {
                                    $powerFunStr = $menuId . '_' . $f['funcode'];
                                    $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                    $checkedF = in_array($powerFunStr, $oldClassfuns) ? 'checked="checked"' : '';
                                    $classFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="classfun[]" value="' . $powerFunStr . '" '.$checkedF.'>' . $f['title'] . '</label>';
                                }
                            }
                            $essayFunHtml = '';
                        }
                        $checkedC = in_array($menuId, $oldClass) ? 'checked="checked"' : '';
                        echo <<<html
                <tr>
                    <td class="$fontb"><label><input type="checkbox" name="classs[]" value="$menuId" $checkedC >$str $menuname</label></td>
                    <td>
                        $classFunHtml
                    </td>
                    <td>
                        $essayFunHtml
                    </td>
                </tr>
html;
                    }
                }
                ?>
            </table>

            <!----------其他权限---------->
            <?php if(!empty($classlistFuns)){ ?>
                <br><div class="titleH18">其他权限</div><br>
                <table class="table_th_td" >
                    <tr class="weight400">
                        <th>控制器名称</th>
                        <th colspan="2">方法权限</th>
                    </tr>
                    <?php
                    foreach($classlistFuns as $menu_id=>$menuname){
                        $fontb = 'fontb';
                        $otherFunHtml = '';
                        $checkedC = in_array($menu_id, $oldClass) ? 'checked="checked"' : '';
                        foreach($otherFuns as $f){
                            if($f['menu_id'] == $menu_id) {
                                $powerFunStr = $menu_id . '_' . $f['funcode'];
                                $displayNo =  $f['flag'] == 1 ? $adminDisplay : '';
                                $checkedF = in_array($powerFunStr, $oldClassfuns) ? 'checked="checked"' : '';
                                $otherFunHtml .= '<label class="'.$displayNo.'"><input type="checkbox" name="classfun[]" value="' . $powerFunStr . '" '.$checkedF.'>' . $f['title'] . '</label>';
                            }
                        }
                        echo <<<html
                <tr>
                    <td class="$fontb"><label><input type="checkbox" name="classs[]" value="$menu_id" $checkedC >$menuname</label></td>
                    <td colspan="2">
                        $otherFunHtml
                    </td>
                </tr>
html;
                    }
                    ?>
                </table>
            <?php } ?>

        </div>
        <div class="form_item" style="text-align: center">
            <br><input type="button" id="sub_btn" value="提交保存" class="btn_base btn_back_sides btn_w300 btn_height35 btn_radius5">
        </div>
    </form>
</div>
</body>
<script language="javascript">
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('info');</script>
<script language="javascript">

    // 加载完毕后
    window.onload = function () {

    }

    // jquery
    var flagSub = true;
    var gotoUrl = '<?php echo SYS_URL_PATH('admin_power_giverule');?>';
    $(function(){
        $('#sub_btn').on('click',function(){
            if(!flagSub){
                layer.msg('处理中……(禁止重复提交)');return false;
            }
            flagSub = false;
            var fromBox = $('.form_box');
            var param = getFormData(fromBox);
            param.append('subFlag', 'Y'); // 追加参数
            $.ajax({
                url:gotoUrl,
                dataType:'json',
                type:'POST',
                async: false,
                data: param,
                processData : false, // 使数据不做处理
                contentType : false, // 不要设置Content-Type请求头
                success: function(data){
                    flagSub = true;
                    if(data=='Y'){
                        layer.msg('保存成功');
                        setTimeout(function(){
                            parent.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },
                error:function(response){
                    flagSub = true;
                    layer.msg('网络异常');
                    console.log('网络异常：'+response);
                }
            });
        })
    })
</script>
</html>